import { Status } from './../app.types';
import { Controller, Get, Post, Body, Query, Request, Res, UseGuards, UseInterceptors } from '@nestjs/common'
import { UserService } from './user.service'
import { User } from './user.entity'
import { AuthGuard } from '@nestjs/passport'
import { CreateUserDto } from './user.dto'
import { LoggingInterceptor } from '../common/interceptors/logging.interceptor'
import { TransformInterceptor } from '../common/interceptors/transform.interceptor'
import { UserCreateResp } from './user.interface'
import { Roles } from '../common/decorators/roles.decorator'
import { RolesGuard }  from '../common/guards/roles.guard'

@Controller('user')
@UseGuards(RolesGuard)
@UseInterceptors(LoggingInterceptor, TransformInterceptor)
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get()
  @Roles('admin')
  // @UseGuards(AuthGuard('jwt'))
  findAll(): Promise<User[]> {
    return this.userService.findAll()
  }

  /*
  @Get('create')
  async create(): Promise<string> {
    return this.userService.create()
  }
  */

  @Post()
  async create(@Body() createUserDto: CreateUserDto, @Res() res): Promise<UserCreateResp> {
    const { code, message } = await this.userService.create(createUserDto)
    return res.status(code).json(message)
  }
}
